﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebAPI.TOM
{
    public partial class TomApi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    string strlinkid = string.Empty,//唯一标识，北京中通
                           strMOMR = string.Empty,//
                           strType = string.Empty,
                           strmobile = string.Empty,//手机号
                           strmsg = string.Empty,//内容 
                           strpid = string.Empty,//通道号码
                           strmoney = string.Empty,//资费 100 表示1.00元
                           strstatus = string.Empty,//状态（0为成功，1失败）
                           strOrderNo = string.Empty;//订单号

                    if (Request.QueryString["linkid"] != null)
                        strlinkid = Request.QueryString["linkid"].ToString().Trim();
                    if (Request.QueryString["mo_mr"] != null)
                        strMOMR = Request.QueryString["mo_mr"].ToString().Trim();
                    if (Request.QueryString["type"] != null)
                        strType = Request.QueryString["type"].ToString().Trim();
                    if (Request.QueryString["mobile"] != null)
                        strmobile = Request.QueryString["mobile"].ToString().Trim();
                    if (Request.QueryString["msg"] != null)
                        strmsg = Request.QueryString["msg"].ToString();
                    if (Request.QueryString["pid"] != null)
                        strpid = Request.QueryString["pid"].ToString();
                    if (Request.QueryString["money"] != null)
                        strmoney = Request.QueryString["money"].ToString().Trim();
                    if (Request.QueryString["status"] != null)
                        strstatus = Request.QueryString["status"].ToString().Trim();
                    if (Request.QueryString["userid"] != null)
                        strOrderNo = Request.QueryString["userid"].ToString().Trim();

                    if (!string.IsNullOrEmpty(strlinkid))
                    {
                        //记录每次请求信息
                        MM.LibraryAPI.TOM.OrderHelper.ReceiveTomInfo(strlinkid, strMOMR, strType, strmobile, strmsg, strpid, strmoney, strstatus, strOrderNo);

                        //下行成功后更新状态
                        if ("0".Equals(strstatus) && "mr".Equals(strMOMR) && !string.IsNullOrEmpty(strOrderNo))
                        {
                            MM.LibraryAPI.Common.SetOrderStatus(strOrderNo);
                        }
                        Response.Write("ok");
                    }
                    else Response.Write("err");
                }
                catch (Exception ex)
                {
                    MM.Common.LogHelp.WriteLogInfo(ex.ToString());
                    Response.Write("err");
                }
            }
        }
    }
}